package com.pointi.PatternExtractor;

public class emoPattern
{
	//____________________________________________________________________________________________________
	// DEF // Parameter Array

	private int length ;
	private double [] min ;
	private double [] max ;

	public int length() {return this.length ; }
	public double min(int idx) { return this.min[idx] ; }
	public double max(int idx) { return this.max[idx] ; }
	
	public void length(int length) { this.length = length ; }
	public void min(int idx, double value) { this.min[idx] = value ; } 
	public void max(int idx, double value) { this.max[idx] = value ; } 

	//____________________________________________________________________________________________________
	// INIT

	public emoPattern(int length)
	{
		this.length = length ;
		this.min = new double[this.length] ;
		this.max = new double[this.length] ;
		this.fnInitialization() ;
	}
	
	public emoPattern(emoPattern range) // COPY
	{
		this.length = range.length() ;
		this.min = new double[this.length] ;
		this.max = new double[this.length] ;
		this.fnInitialization(range) ; 
	}

	public void fnInitialization()
	{
		for(int i=0; i<this.length(); i++)
		{
			this.min(i, 0.0) ;
			this.max(i, 0.0) ;
		}
	}
	
	public void fnInitialization(emoPattern range)
	{
		for(int i=0; i<range.length(); i++)
		{
			this.min(i, range.min(i)) ;
			this.max(i, range.max(i)) ;
		}
	}
	
	//____________________________________________________________________________________________________
	// DB

	public String fnGetQuery(String date, emoParam param)
	{
		String query = "" ;
		String table = "t_pe_result" ; //TODO TEMPORARY NAME //
		query = "INSERT INTO " + table + date + " (" ;
		
		for(int i=0; i<param.length(); i++)
		{
			query += (param.param(i) + "_min" + " , ") ;
			query += (param.param(i) + "_max") ;
			if((i+1)!=param.length()) query +=  " , " ; 
		}
		query += ") VALUES (" ;
		for(int i=0; i<this.length(); i++)
		{
			query += min[i] + " , " ; 
			query += max[i] ;
			if((i+1)!=this.length()) query +=  " , " ;
		}
		query += ") ;" ;
		System.out.println(query) ;
		return query ;
	}

	//____________________________________________________________________________________________________
	// PRINT 
	
	public void fnPrint(emoParam param)
	{
		for(int i=0; i<this.length; i++)
		{
			System.out.print(String.format("%s_min\t\t%s_max\t\t", param.param(i), param.param(i))) ;
		}
		System.out.print("\n") ;
	}
	
	public void fnPrint()
	{
		for(int i=0; i<this.length; i++)
		{
			System.out.print(String.format("%f\t%f\t", this.min(i), this.max(i))) ;
		}
		System.out.println("") ;
	}
	
	public void fnPrint(emoParam param, String date)
	{
		// PREPARE
		String t_bd_full_log = "t_bd_full_log_" + date ;
		// QUERY
		String query = "" ;
		query = "SELECT COUNT(*) AS 'cnt' FROM " + t_bd_full_log + " AS F WHERE "  ;
		for(int i=0; i<param.length(); i++)
		{
			if(i!=0) query += " AND " ;
			query += String.format("(%f <= F.%s AND F.%s <= %f)", this.min(i), param.param(i), param.param(i), this.max(i)) ;
		}
		System.out.println(query) ;
		System.out.println("") ;
	}

	//____________________________________________________________________________________________________
	// EOC
}
